#include<stdio.h>
int main(int argc, char *argv[])
{
    if(argc != 2) 
    {
        printf("argv error!\n");
        return 1;
    }

    //FILE* fopen(const char* path, const char* mode);
    FILE* fp = fopen(argv[1], "r"); /* ./myfile test.txt */
    if(fp == NULL)
    {
        perror("fopen");
        return 2;
    }

    //按行读取
    char line[64];
    //char* fgets(char* s, int size, FILE * stream);  
    // fgetstring -- fgets 自动在所读取的字符结尾添加\0
    while(fgets(line, sizeof(line), fp) != NULL)
    {
        //printf("%s", line);
        fprintf(stdout, "%s", line);
    }

    //文件操作
    //size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE* stream);
    //const char *s1 = "hello file\n"; 
    //fwrite(s1, strlen(s1), 1, fp);

    //const char *s2 = "hello fprintf\n";
    //fprintf(fp, "%s", s2);

    //const char *s3 = "hello fputs\n";
    //fputs(s3, fp); int fputs(const char *s, FILE *stream);

    fclose(fp);

    return 0;
}
